<?php
// swoole版本在4.3之前的写法
$conf = [
    'host' => '192.168.1.40',
    'port' => 3306,
    'user' => 'root',
    'password' => 'root',
    'database' => 'studyswoole',
    'charset'  => 'utf8mb4',
    'timeout'  => 2
];
$db = new swoole_mysql();
$db->connect($conf, function ($db, $r) {
    if ($r === false) {
        var_dump($db->connect_errno, $db->connect_error);
        die;
    }
    $table = "student";
    $sql = "select * from {$table} limit 10";
    $db->query($sql, function ($db, $r) {
        if($r === false) {
            var_dump($db->error, $db->errno);
        } elseif ($r === true) {
            foreach ($r as $value) {
                var_dump($value);
            }
        }
        $db->close();
    });
});
